import { Game } from "@sapi-game/main";
import { Duration } from "@sapi-game/utils";
import { PKEndState } from "@/parkour/endState/endState";
import { parkourGameModule } from "@/parkour/module";
import { PKParkourConfig } from "./interface";
import { PKParkourState } from "./pkParkourState";

export class PKParkourControlState extends parkourGameModule.State {
    process: PKParkourConfig[] = [
        //自己测试
        {
            team: this.context.blue.team,
            isTest: true,
            baseLocation: this.context.blue.base,
            volume: this.context.blue.volume,
        },
        {
            team: this.context.red.team,
            isTest: true,
            baseLocation: this.context.red.base,
            volume: this.context.red.volume,
        },
        //交换场地
        {
            team: this.context.red.team,
            isTest: false,
            baseLocation: this.context.blue.base,
            volume: this.context.blue.volume,
        },
        {
            team: this.context.blue.team,
            isTest: false,
            baseLocation: this.context.red.base,
            volume: this.context.red.volume,
        },
    ];

    curProcess = 0;

    override onEnter(): void {
        this.subscribe(
            Game.events.interval,
            () => {
                if (this.nextState == undefined) {
                    if (this.curProcess >= this.process.length) {
                        this.transitionTo(PKEndState);
                    } else {
                        this.pushState(
                            PKParkourState,
                            this.process[this.curProcess++]
                        );
                    }
                }
            },
            new Duration(20)
        );
    }
}
